/* eslint-disable no-unused-vars */
import React from 'react';
import {NavigationContainer, DefaultTheme} from '@react-navigation/native';
import {navigationRef} from '../../utils/index';
import RootStack from './RootStack';

const MyTheme = {
  ...DefaultTheme,
  colors: {
    ...DefaultTheme.colors,
    primary: '#333',
    background: '#fff',
  },
};

// Gets the current screen from navigation state
const getActiveRouteName = state => {
  const route = state.routes[state.index];

  if (route.state) {
    // Dive into nested navigators
    return getActiveRouteName(route.state);
  }
  return route.name;
};

class Navigator extends React.Component {
  state = {
    navigationState: undefined,
  };

  onStateChange = state => {
    this.setState(
      {
        navigationState: state,
      },
      () => {
        // const previousRouteName = fondPreviousRouteNameFromNavigatorState(
        //   state,
        // );
        // const currentRouteName = findRouteNameFromNavigatorState(state);
        // // 分析统计sdk
        // if (previousRouteName !== currentRouteName) {
        //   analytics().setCurrentScreen(currentRouteName, currentRouteName);
        // }
      },
    );
  };

  render() {
    return (
      <NavigationContainer
        theme={MyTheme}
        onStateChange={this.onStateChange}
        ref={navigationRef}>
        <RootStack />
      </NavigationContainer>
    );
  }
}

export default Navigator;
